function H = gabor_fker(siz, sigma, lambda, angle)
%GABOR_FKER Gabor filter kernel
%
%   H = gabor_fker(siz, sigma, lambda);
%   H = gabor_fker(siz, sigma, lambda, angle);
%
%       Constructs a real-valued Gabor filtering kernel.
%
%       Input arguments:
%       - siz:      The size of the filter kernel, which can be either
%                   a scalar, or a pair in form of [a, b].
%
%       - sigma:    The standard deviation of the Gassian envelope.
%                   It can be either a scalar, or a pair in form of
%                   [sig_x, sig_y] if they are not equal.
%
%       - lambda:   The wavelength of the sinusoidal wave.
%
%       - angle:    The orientation angle (counterclockwisely).
%                   If omitted, it is set to 0.
%

% Created by Dahua Lin, on April 4, 2012
%

%% parse arguments

if isscalar(siz)
    h = siz;
    w = siz;
elseif numel(siz) == 2
    h = siz(1);
    w = siz(2);
else
    error('gabor_fker:invalidarg', 'siz should be either a scalar or a pair.');
end

if ~(rem(h, 2) == 1 && rem(w, 2) == 1)
    error('gabor_fker:invalidarg', 'kernel dimensions should be odd integers.');
end

if isscalar(sigma)
    sig_x = sigma;
    sig_y = sigma;
elseif numel(sigma) == 2
    sig_x = sigma(1);
    sig_y = sigma(2);
else
    error('gabor_fker:invalidarg', 'sigma should be either a scalar or a pair.');
end

if nargin < 4
    angle = 0;
end

%% main

[X, Y] = fker_xymap(h, w, angle);

B = exp( - X.^2 * (1/(2*sig_x^2)) - Y.^2 * (1/(2*sig_y^2)) );
M = cos((2*pi/lambda) * X);

H = B .* M;




